import { tianyanchaDetail } from "@/api"
import type { OnchangeArgument } from "../types";
import { IsInternalInterfaceEnum } from "@/enums/formEnum";

/**
 * @description 获取天眼查回填内容
 * @date 24/04/2023
 * @export
 * @param {OnchangeArgument} event
 */
export async function getTianyanchaDetail(event: OnchangeArgument) {
  const { val, isInternalInterface } = event
  if (isInternalInterface !== IsInternalInterfaceEnum.TIANYANCHA) return
  try {
    const res = await tianyanchaDetail(val)
    const values: Recordable = {};
    for (const k in res) {
      values[k] = res[k];
    }
    return values
  } catch (error) {
    uni.showModal({
      title: '提示',
      content: '企业数据回显失败, 是否重新尝试?',
      success: ({ confirm }) => confirm && getTianyanchaDetail(val),
    });
  }
}